﻿@model SDCloudSolution.SDCloud.Web.Models.Model.ModelEditViewModel

@{
    Layout = MVC.Shared.Views._AuthorizedLayout;
    if (Model.ModelId > 0)
    {
        ViewBag.Title = "Edit " + Model.Name;
    }
    else
    {
        ViewBag.Title = "Create model";
    }
}

@section scripts {
    <script src="~/Scripts/js/libs/require/require.js"></script>
    <script src="~/Scripts/app.js"></script>
    <script src="~/Scripts/sdCloud/edit.model.js"></script>
}

<h1>
    @if (Model.ModelId > 0)
    {
        @Html.Raw("Edit model")
    }
    else
    {
        @Html.Raw("Create model")
    }
</h1>

<div id="edit-model">
    @using (Html.BeginForm(MVC.Models.Save(), FormMethod.Post, new { @class = "oj-lg-form-across", enctype = "multipart/form-data" }))
    {
        @Html.ValidationSummary()

        @Html.HiddenFor(model => model.ModelId)

        <div class="oj-flex oj-flex-items-pad">
            @Html.LabelFor(model => model.Name, new { @class = "oj-sm-12 oj-lg-9 oj-xl-6 oj-flex-item" })
            <div class="oj-sm-12 oj-flex-item">
                @Html.TextBoxFor(model => model.Name, new { @class = "oj-sm-12 oj-lg-9 oj-xl-6 oj-flex-item oj-form-control" })
            </div>
        </div>

        <div class="oj-flex oj-flex-items-pad">
            @Html.LabelFor(model => model.Description, new { @class = "oj-sm-12 oj-lg-9 oj-xl-6 oj-flex-item" })
            <div class="oj-sm-12 oj-flex-item">
                @Html.TextAreaFor(model => model.Description, new { @class = "oj-sm-12 oj-lg-9 oj-xl-6 oj-flex-item oj-form-control", rows = 15 })
            </div>
        </div>
            <br />
            <div class="oj-flex oj-flex-items-pad">
                @Html.LabelFor(model => model.ModelFile, new { @class = "oj-sm-12 oj-lg-9 oj-xl-6 oj-flex-item oj-form-control" })
                <div class="oj-sm-8 oj-flex-item">

                    @if (!string.IsNullOrEmpty(Model.CurrentFileName))
                {
                        @Html.HiddenFor(model => model.CurrentFileName)
                        <div>
                            <span class="glyphicon glyphicon-file"></span>
                            @Model.CurrentFileName
                        </div>
                    }

                    <input type="file" name="@Html.NameFor(model => model.ModelFile)" class="form-control" />
                </div>
            </div>
            <br />
            <div class="oj-flex oj-flex-items-pad">
                @if (Model.ModelId > 0)
                {
                    <div class="oj-sm-8 oj-flex-item">
                        <input type="submit" class="oj-button-confirm"
                               data-bind="ojComponent: {component: 'ojButton', label: 'Save'}" />
                        <a href="@Url.Action(MVC.Models.View(Model.ModelId))"
                           data-bind="ojComponent: {component: 'ojButton'}">Cancel</a>
                    </div>
                }
                else
                {
                    <div class="oj-sm-8 oj-flex-item">
                        <input type="submit" class="oj-button-confirm"
                               data-bind="ojComponent: {component: 'ojButton', label: 'Create'}" />
                        <a href="@Url.Action(MVC.Models.List())"
                           data-bind="ojComponent: {component: 'ojButton'}">Cancel</a>
                    </div>
                }
            </div>
    }
</div>

